//
//  ST_DTChatEmojiCell.swift
//  btvideo
//
//  Created by mac on 2020/7/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit


class ST_DTChatEmojiCell: ST_DTChatCell {
    
    override func commonInit() {
        super.commonInit()
    }
    
    static let height = (85+15).cgFloat
    
    fileprivate lazy var box_view:UIView = {
       let control = UIView()
        control.backgroundColor = .white
//        control.borderColor = UIColor.init(hex: 0xF2F4F7)
//        control.borderWidth = 1
//        control.cornerRadius = 20
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(click_goods))
        
        control.addGestureRecognizer(tap)
        
        return control
    }()
    
    @objc fileprivate func click_goods(){
        
        
    }
    
    fileprivate lazy var emoji_image_view:UIImageView = {
       let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
   
    
    
    override var message: ST_DTChatMessage!{
        didSet{
            
            if uuid == message.uuid{
                return
            }
            
            
            self.uuid = message.uuid
            
            icon.sd_setImage(with: message.portraitUri.compress_image().url,for: UIControl.State.normal, completed: nil)
            
            guard let emoji = message.emoji else { return  }
            
            emoji_image_view.pin_setImage(from: emoji.imageUrl.url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            }
    }
}




//MARK: - Left


class ST_DTChatEmojiLeftCell: ST_DTChatEmojiCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func commonInit() {
        super.commonInit()
        
        icon.snp.makeConstraints { (make) in
            make.width.height.equalTo(DTChatUserImageWidth)
            make.left.top.equalToSuperview().offset(15)
        }
        
        contentView.addSubview(box_view)
        box_view.snp.makeConstraints { (make) in
            make.width.equalTo(85)
            make.height.equalTo(85)
            make.left.equalTo(icon.snp.right).offset(4)
            make.top.equalTo(icon)
        }
        
        box_view.addSubview(emoji_image_view)
        emoji_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 12, left: 15, bottom: 11, right: 15))
        }
        
        self.contentView.addSubview(tailView)
        tailView.snp.makeConstraints { (make) in
            make.height.equalTo(17)
            make.top.equalTo(box_view.snp.bottom).offset(5)
            make.left.equalTo(box_view)
        }
        
    }
    
    fileprivate lazy var tailView:ST_ChatMessageTailControl = {
         let control = ST_ChatMessageTailControl()
          return control
      }()
    
    override var message: ST_DTChatMessage!{
        didSet{
         
            tailView.model = self.message.tail
            
        }
    }
}


//MARK: - Right
class DTChatEmojiRightCell: ST_DTChatEmojiCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func commonInit() {
        super.commonInit()
    
        contentView.addSubview(box_view)
        box_view.snp.makeConstraints { (make) in
            make.width.equalTo(85)
            make.height.equalTo(85)
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(15)
        }
        
        box_view.addSubview(emoji_image_view)
        emoji_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 12, left: 15, bottom: 11, right: 15))
        }
        
        
        
        
        contentView.addSubview(upload_error_btn)
        upload_error_btn.snp.makeConstraints { (make) in
            make.centerY.equalTo(box_view)
            make.right.equalTo(box_view.snp.left).offset(-8)
            make.width.height.equalTo(16)
        }
        
        contentView.addSubview(uploadIndicator)
        uploadIndicator.snp.makeConstraints { (make) in
            make.centerY.equalTo(box_view)
            make.right.equalTo(box_view.snp.left).offset(-8)
        }
    }
    
   
    override func setting_uplaod_status() {
        
        if message.uploadStatus == .uploading {
            
            uploadIndicator.startAnimating()
            
        }else{
            uploadIndicator.stopAnimating()
        }
        
        upload_error_btn.isHidden = message.uploadStatus != .failure
    }
    
}
